<?php
error_reporting(E_ALL);
define('RAIZ','..');
header('Content-Type:text/html;Charset=UTF-8');
session_name('adminctl');
require './admins.php';
require '../config.php';
require '../juegoinclude/init.php';
if(!isset($_SESSION['ContextoAdmin'])){
    define('FICHERO_IDIOMA','login.php');
    require '../juegoinclude/idioma.php';
    if(isset($_POST['Usuario'],$_POST['Contrasena'])){
        foreach($Admins as $Admin){
            if($Admin['Nombre'] == $_POST['Usuario']){
                $Contrasena = ($Admin['Encriptada']) ? (md5(PREFIJO_MD5 . $_POST['Contrasena'])) : $_POST['Contrasena'];
                if($Admin['Contrasena'] == $Contrasena){ // Contraseña correcta
                    $_SESSION['ContextoAdmin'] = $Admin;
                    die('<script>window.location.href=".";</script>');
                    exit;
                }
            }
        }
        echo '<script>alert("' . $L['ERR_USUARIO_INVALIDO'] . '");</script>';
        exit;
    }
    ?>
    <html>
        <head>

            <title>Hyperspace Masters Administracion</title>
	    <link rel="shortcut icon" href="../archivos/logo.ico">
            <script src="../scripts/jquery-1.10.2.min.js"></script>
            <script src="../scripts/funciones.js"></script>
            <script src="../scripts/login.eventos.js"></script>
            <script src="../idiomas/<?php echo $IDIOMA;?>/global.js"></script>
        </head>
        <body>
            <form id="formLogin" name="Login" method="post" action=".">
            <?php echo $L['USUARIO'];?>: <input type="text" name="Usuario"/><br />
            <?php echo $L['CONTRASENA'];?>: <input type="password" name="Contrasena"/><br />
            <input type="button" onclick="iniciarSesion(this,'#formLogin');" value="<?php  echo $L['ADMINISTRAR'];?>"/>
            </form>
            <div id="RAJAX" style="display: none;"></div>
        </body>
    </html>
    <?php
}else{
    require './bodyadmin.php'; 
               
}